
//% color="#ef784c" iconWidth=50 iconHeight=40
namespace matplotlib{

    
    //% block="matplotlib begin " blockType="command"


    export function matplotlib_Iint(parameter: any, block: any) {

        
        Generator.addImport(`from matplotlib import pyplot as plt\nimport matplotlib\n`)

        
        
    }
    //% block="matplotlib_Iintsize  begin [WIDE] [HIGH] DPI[DPI]" blockType="command"
    //% WIDE.shadow="number" WIDE.defl="8"
    //% HIGH.shadow="number" HIGH.defl="3"
    //% DPI.shadow="number" DPI.defl="80"

    export function matplotlib_Iintsize(parameter: any, block: any) {
        let wide=parameter.WIDE.code;
        let high=parameter.HIGH.code;
        let dpi=parameter.DPI.code;

        
        Generator.addCode(`plt.figure(figsize=(${wide}, ${high}),dpi=${dpi})`)

        
    } 


    //% block="---"
    export function noteSep2() {

    }
    //% block="matplotlib_rcParams[FONT][TX] " blockType="command"
    //% FONT.shadow="string" FONT.defl="font.sans-serif"
    //% TX.shadow="string" TX.defl="HYQiHei"
    export function matplotlib_rcParams(parameter: any, block: any) {
        let font=parameter.FONT.code;
        let tx=parameter.TX.code;       
        Generator.addCode(`plt.rcParams[${font}] = [${tx}]`)
        
    }
    //% block="matplotlib_subplots_adjust [LEFT] [BOTTOM]" blockType="command"
    //% LEFT.shadow="range" LEFT.params.min=1  LEFT.params.max=100  LEFT.defl=20
    //% BOTTOM.shadow="range" BOTTOM.params.min=1 BOTTOM.params.max=100 BOTTOM.defl=10

    export function matplotlib_subplots_adjust(parameter: any, block: any) {
        let left=parameter.LEFT.code;
        let bottom=parameter.BOTTOM.code;

        
        Generator.addCode(`plt.subplots_adjust(left=${left}/100,bottom=${bottom}/100)`)
        // Generator.addCode(`plt.subplots_adjust(left=${left},bottom=${bottom},right=${right},top=${top},wspace=${ws},hspace=${hs})`)
        
    } 
    //% block="matplotlib_title[TX][COLOR][SIZE] " blockType="command"
    //% TX.shadow="string" TX.defl='标题内容'
    //% COLOR.shadow="dropdown" COLOR.options="COLOR"
    //% SIZE.shadow="string" SIZE.defl="10"
    export function matplotlib_title(parameter: any, block: any) {
  
        let tx=parameter.TX.code;
        let color=parameter.COLOR.code;  
        let size=parameter.SIZE.code;         
        Generator.addCode(`plt.title(${tx},color='${color}',size=${size}) `)
        
    }
    //% block="matplotlib_label[LABEL][TXET][SIZE]" blockType="command"
    //% LABEL.shadow="dropdown" LABEL.options="LABEL"
    //% TXET.shadow="string" TXET.defl="X轴"
    //% SIZE.shadow="number" SIZE.defl="10"
    export function matplotlib_label(parameter: any, block: any) {
        let label=parameter.LABEL.code;
        let text=parameter.TXET.code;
        let size=parameter.SIZE.code;
        Generator.addCode(`plt.${label}label(${text}, fontsize=${size})`)
            
        

    }   



    
        //% block="---"
        export function noteSep1() {

        }
    //% block="matplotlib_Iintplotpie  [X] [LABELS] [COLOR] [AUTOPCT] [EXPLODE][SHADOW]   " blockType="command"
     
    //% X.shadow="list" X.defl="30,20,50"
    //% LABELS.shadow="list" LABELS.defl="'数据1','数据2','数据3'"
    //% COLOR.shadow="list" COLOR.defl="'yellow','red','blue'"
    //% AUTOPCT.shadow="dropdown" AUTOPCT.options="AUTOPCT" 
    //% EXPLODE.shadow="list" EXPLODE.defl="0,0.1,0"
    //% SHADOW.shadow="dropdown" SHADOW.options="SHADOW" 
        

    export function matplotlib_Iintplotpie(parameter: any, block: any) {
        let x=parameter.X.code;
        let labels=parameter.LABELS.code;
        let color=parameter.COLOR.code;
        let autopct=parameter.AUTOPCT.code;
        let explode=parameter.EXPLODE.code;
        let shadow=parameter.SHADOW.code;
        // console.log(shadow)
        
        Generator.addCode(`plt.pie(${x},labels=${labels},autopct='${autopct}',explode=${explode},shadow=${shadow})`)


    } 


    //% block="matplotlib_Iint[GRAPHICS] [X] [Y]" blockType="command"
    //% GRAPHICS.shadow="dropdown" GRAPHICS.options="GRAPHICS"
    //% X.shadow="list" X.defl="1,2"
    //% Y.shadow="list" Y.defl="2,4"
    

    export function matplotlib_Iintplot(parameter: any, block: any) {
        let graphics=parameter.GRAPHICS.code;
        let x=parameter.X.code;
        let y=parameter.Y.code;
       
 
        Generator.addCode(`plt.${graphics}(${x},${y})`)


    }
    //% block="---"
        export function noteSep() {

    }
    //% block="设置[LABEL]标签旋转[NUM]度" blockType="command"
    //% LABEL.shadow="dropdown" LABEL.options=LABEL
    //% NUM.shadow="normal" NUM.defl="0"
    export function matplotlib_Iintshow1(parameter: any, block: any) {
        let label=parameter.LABEL.code; 
        let num=parameter.NUM.code; 
        Generator.addCode(`plt.${label}ticks(rotation=${num})`)
        
    }
    //% block="matplotlib_Iint [COMMAND]" blockType="command"
    //% COMMAND.shadow="dropdown" COMMAND.options=COMMAND
    export function matplotlib_Iintshow(parameter: any, block: any) {
        let command=parameter.COMMAND.code; 
        Generator.addCode(`plt.${command}()`)
        
    }
    //% block="matplotlib_Iint pause [TIME]" blockType="command"
    //% TIME.shadow="number" TIME.defl="5"
    export function matplotlib_Iintpause(parameter: any, block: any) {
        let time=parameter.TIME.code;    
        Generator.addCode(`plt.pause(${time})`)
        
    }  

    //% block="matplotlib_IintFonts  " blockType="reporter"
    
    export function matplotlib_IintFonts(parameter: any, block: any) {
           
        Generator.addCode(`sorted([f.name for f in matplotlib.font_manager.fontManager.ttflist])`)
        
    }  
}
